<?php
 require "./config/mysql.php";
 class kidList extends mysqlPdo

 {
   public static function addkid($king,$explanation)

   {
    $pdo = mysqlPdo::getPdoConnect();
    $tr = $pdo -> exec("insert into article_kind (king,explanation) values ('$king','$explanation')");
    return $tr;
   }


   public static function getkidinfo()

   {
    $pdo = mysqlPdo::getPdoConnect();
    $tr = $pdo -> query("select * from article_kind ");
    $str = $tr -> fetchAll(PDO::FETCH_ASSOC);
    $total = $tr -> rowCount();   //获取总记录数;
    $num = 4;             //每页显示的记录数;
    $url = "control_kid.php";          //请求的URL 
    $cpage = isset($_GET["page"]) ? $_GET["page"] : 1;//当前页  
    $pagenum = ceil($total/$num);//总页数 
    $offset = ($cpage-1)*$num;//开始去数据的位置  
    $sql1 = "select * from article_kind order by id desc limit {$offset},{$num}";
    $tr1 = $pdo -> query($sql1);
    $str1 = $tr1 -> fetchAll(PDO::FETCH_ASSOC);
    $start = $offset+1;//开始记录页 
    $end = ($cpage==$pagenum) ? $total : ($cpage*$num);//结束记录页 
    $next = ($cpage==$pagenum) ? $pagenum : ($cpage+1);//下一页  
    $prev = ($cpage==1) ? 1 : ($cpage-1);//前一页  
    $arr = array(
        'total'=>$total,
        'num'=>$num,
        'url'=>$url,
        'cpage'=>$cpage,
        'pagenum'=>$pagenum,
        'offset'=>$offset,
        'str1'=>$str1,
        'start'=>$start,
        'end'=>$end,
        'next'=>$next,
        'prev'=>$prev,
        );
        return $arr;

   }


   public static function getinfo($id)

   {
    $pdo = mysqlPdo::getPdoConnect();
    $tr = $pdo -> query("select * from article_kind where id = $id");
    $str = $tr -> fetchAll(PDO::FETCH_ASSOC);
    return $str;
   }


    public static function changekid($king,$explanation,$id)

   {
    $pdo = mysqlPdo::getPdoConnect();
    $tr = $pdo -> exec("update article_kind set king = '$king',explanation = '$explanation' where id = $id");   
    return $tr;
   }

    public static function delekid($id)

   { 
     $pdo = mysqlPdo::getPdoConnect();
     $tr = $pdo -> exec("delete from article_kind where id=$id");
     $tr1 = $pdo -> exec("delete from article_content where kid=$id");
     return $tr;
   }




 }